package com.example.Mapper;

import org.apache.ibatis.annotations.*;

import com.example.pojo.Belaidup;
import com.example.pojo.Belaidupcong;
import com.example.pojo.oderfrom;

import java.util.List;
public interface CgRkDao {
//分页查询主表
 @Select("select * from Belaidup as b  inner join gongyingshang as g on b.custid=g.gysid where  b.zhuangtai!='无效' order by billno desc limit #{page},1")
 Belaidup List(@Param("page")int page);
 /*查询有多少记录数*/
 @Select("select count(1) from Belaidup  where  zhuangtai!='无效'")
 int selectCount();
 /*按照主表外键查询从表*/
 @Select("select * from Belaidupcong  as a inner join materialzhu  as b  on a.ProdId=b.ProdId  where 	Pk_id=#{id}")
 List<Belaidupcong>  cList(@Param("id")String id);
 //新增入库主表
 @Insert("insert into Belaidup values(#{custID},#{billDate},#{billNO},#{classID},#{currID},#{priceofTax},#{exchRate},#{wareid},#{hasForeignTrade},#{pK_pingzheng},#{salesID},#{maker},#{departName},#{permitter},#{projectName},#{zhuangtai},#{zongjine})")
 void Insertrk(Belaidup b );
 //新增入库从表
 @Insert("insert into Belaidupcong values(#{Line},#{ProdId},#{danwei},#{Shuliang},#{Zhikoudanjia},#{zheshu},#{price},#{Jine},#{Shuilv},#{Shuie},#{Hanshuiprice},#{Danbie},#{BillNo},#{Pk_id},#{Fentang},#{isgift},#{Remake},#{DueTo},#{PrepayDay},#{AccMonth},#{tiaojian})")
 void Insertrkxx(Belaidupcong b1 );
 //按照入库编号删除入库从表
 @Delete("delete from Belaidupcong where Pk_id=#{id}")
 void Delete(@Param("id")String d);
 //按照入库编号删除入库主表
 @Delete("delete from Belaidup where BillNo=#{id}")
 void Deletezhu(@Param("id")String d);
 //修改入库主表为已审核
 @Update("update belaidup   set zhuangtai='已审核' where BillNO=#{id}")
 void upadte1(@Param("id") String no);
 //修改入库主表为未审核
 @Update("update belaidup   set zhuangtai='未审核' where BillNO=#{id}")
 void upadte2(@Param("id") String no);
 //删除入库主表
 @Update("update belaidup   set zhuangtai='无效' where BillNO=#{id}")
 void upadte3(@Param("id") String no);
 //采购订单转单查询
 @Select("select * from oderfrom where shifoushenhe='已审核'and  BillStatus='未结案'  and Billdate<#{time}")
 List<oderfrom>  findorder(@Param("time") String time);
 //采购订单主表查询
 @Select("select 	Customerid as CustID, Billdate as Billdates, Billno as billnos, Currid, Shifoushenhe, Sumtotal, Priceoftax, Billstatus, Exchrate, Maker, Salesid, Permitter, Departname, Projectid,GYSname,GYSaddress from oderfrom  as b  inner join gongyingshang as g on b.customerid=g.gysid where billno=#{id}")
 Belaidup  cList1(@Param("id") String no);
 //采购订单从表转单查询
 @Select("select 	Serno as Line, billno ,a.ProdId, oldprice as Zhikoudanjia, discount as zheshu, sPrice as price, squantity ,amount as Jine, Vftotal as Hanshuiprice, Preindate , Qtyremain  as Shuliang, taxrate as Shuilv, taxamt as Shuie , trantype, fromno, isgift,prodname "
 		+ "from oderfromcong as a inner join materialzhu as b on a.ProdId=b.ProdId where billno=#{id} and Qtyremain>0")
 List<Belaidupcong>  cList2(@Param("id") String no);
 //修改采购订单的未入库量
 @Update("update oderfromcong set QtyRemain=(QtyRemain-#{Shuliang}) where BillNO=#{BillNo} and SerNO=#{Line}")
 void   updatedd1(Belaidupcong b);
 //判断订单数量是否全部入库
 @Select("select * from belaiupjy where billno=#{id}")
 List<Belaidupcong> selectdd(@Param("id") String no);
 //修改采购订单的状态
 @Update(" update  oderfrom set BillStatus='已结案' where BillNO=#{id}")
 void updatedd2(@Param("id")String no);
 //判断订单是否进行过转单
 @Select("select count(1) from belaiupjy where billno=#{BillNo}")
 int Selectjy(Belaidupcong b);
 //向实际入库交易单添加数据
 @Insert("insert into belaiupjy values(#{BillNo},#{ProdId},#{squantity})")
 void Insertjy(Belaidupcong b);
 //实际入库值修改
 @Update("update belaiupjy set shuliang=(shuliang-#{Shuliang}) where billno=#{BillNo} and prodId=#{ProdId}")
 void Updatejy(Belaidupcong b);
}
